﻿using Microsoft.Extensions.Configuration;
using StarsAdmin.Core.Helpers;
using Yitter.IdGenerator;

namespace StarsAdmin.Core.App.Models
{
    public class SnowIdOptions : IdGeneratorOptions
    {
        private readonly IConfiguration _configuration;

        public SnowIdOptions(IConfiguration configuration)
        {
            _configuration = configuration.NotNull();
            Initialize();
        }

        //private ushort _workerId;
        //private byte _workerIdBitLength;
        //private byte _seqBitLength;
        //public ushort WorkerId { get => _workerId; }

        //public byte WorkerIdBitLength { get => _workerIdBitLength; }

        //public byte SeqBitLength { get => _seqBitLength; }

        private void Initialize()
        {
            var connectionStrings = _configuration.GetSection("SnowId").NotNull();
            WorkerId = ushort.Parse(connectionStrings.GetSection("WorkerId").Value.NotNull());
            WorkerIdBitLength = byte.Parse(connectionStrings.GetSection("WorkerIdBitLength").Value.NotNull());
            SeqBitLength = byte.Parse(connectionStrings.GetSection("SeqBitLength").Value.NotNull());
        }
    }
}